package com.dh.service.impl;

import com.dh.core.config.Constant;
import com.dh.entity.UserPositive;
import com.dh.repository.UserPositiveRepository;
import com.dh.service.UserPositiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

@Service
public class UserPositiveServiceImpl implements UserPositiveService {

    @Autowired
    UserPositiveRepository positiveRepository;

    @Override
    public Page<UserPositive> page(PageRequest pageRequest) {
        return positiveRepository.findByDeleted(Constant.NOT_DELETE, pageRequest);
    }

    @Override
    public UserPositive get(Long positiveId) {
        return positiveRepository.findOne(positiveId);
    }

    @Override
    public void delete(Long positiveId) {
        //        UserPositive positive = positiveRepository.findOne(positiveId);
        //        positive.setDeleted(Constant.DELETE);
        //        positiveRepository.save(positive);
        positiveRepository.delete(positiveId);
    }

    @Override
    public void create(UserPositive positive) {
        positiveRepository.save(positive);
    }

    @Override
    public void update(UserPositive positive) {
        positiveRepository.save(positive);
    }

    @Override
    public UserPositive findByNoAndDeleted(String no, byte deleted) {
        return positiveRepository.findByNoAndDeleted(no, deleted);
    }
}
